package com.hwadee.teachingprocessmanagementsystem.dto;

import com.hwadee.teachingprocessmanagementsystem.entity.Menu;
import com.hwadee.teachingprocessmanagementsystem.entity.User;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @Description: 登录用户数据传输对象
 * @Author: Jukomu
 * @Package: com.hwadee.teachingprocessmanagementsystem.dto
 * @Project: TeachingProcessManagementSystem
 * @name: LoginUserDto
 * @Date: 2024/7/11-21:24
 * @Filename: LoginUserDto
 */
@Data
public class LoginUserDto implements Serializable {
    private UserInfo userInfo;
    // 用户权限能够访问的目录
    private List<Menu> menuList;
    private String token;
    private String username;

    public LoginUserDto() {
    }
    public LoginUserDto(User user) {
        setUserInfo(user);
    }
    public void setUserInfo(User user) {
        this.userInfo = new UserInfo(user);
    }
}

/**
 * 定义用户信息对象
 */
@Data
class UserInfo {
    private String uid;
    private String role;
    private String referenceId;

    public UserInfo(User user) {
        this.uid = user.getUid();
        this.role = User.getRole(user).toString();
        this.referenceId = user.getReferenceId();
    }
}
